package com.googlecode.contests_repo.core.config;

import java.io.IOException;
import java.util.Properties;

/**
 * Provides configuration properties for the system.
 * 
 * @author deni, joro
 */
public class ConfigurationManager {

	private static ConfigurationManager instance;
	
	private Properties properties;
			
	// hiding the constructor
	private ConfigurationManager() throws IOException {		
		properties = new Properties();
		properties.load(getClass().getResourceAsStream("/config.properties"));
	}
	
	/**
	 * Gets the single instance of the ConfigurationManager.
	 * 
	 * @return
	 * 		the ConfigurationManager
	 */
	public static ConfigurationManager getInstance() {
		if (instance == null) {
			try {
				instance = new ConfigurationManager();
			} catch (IOException e) {
				System.out.println("Could not load properties file!");
				e.printStackTrace();
			}
		}
				
		return instance;
	}
	
	/**
	 * Gets the property with the specified key.
	 * 
	 * @param key
	 * 		the property key
	 * @return
	 * 		the property value
	 */
	public String getProperty(String key) {
		return properties.getProperty(key);
	}
	
	/**
	 * Gets the main directory in which users are stored.
	 * 
	 * @return
	 * 		the main directory in which users are stored
	 */
	public String getUsersDirectory() {
		return properties.getProperty("usersDir");
	}
	
	/**
	 * Gets the main directory in which repository is stored.
	 * 
	 * @return
	 * 		the main directory in which repository is stored
	 */
	public String getRepoRoot() {
	    return properties.getProperty("repoRoot");
	}

	/**
	 * Gets the name of the file with security metadata.
	 * 
	 * @return
	 * 		the name of the file with security metadata
	 */
	public String getSecurityFileName()
	{
	    return properties.getProperty("securityFileName");
	}
}
